package io.renren.modules.work.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.utils.ConfigConstant;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.work.entity.ScQuotationEntity;
import io.renren.modules.work.service.ScQuotationService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;



/**
 * 报价单
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-05-24 22:24:59
 */
@RestController
@RequestMapping("work/scquotation")
public class ScQuotationController {
    @Autowired
    private ScQuotationService scQuotationService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("work:scquotation:list")
    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = scQuotationService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{quotationid}")
    @RequiresPermissions("work:scquotation:info")
    public R info(@PathVariable("quotationid") String quotationid){
		ScQuotationEntity scQuotation = scQuotationService.getById(quotationid);

        return R.ok().put("scQuotation", scQuotation);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("work:scquotation:save")
    public R save(@RequestBody ScQuotationEntity scQuotation){
        scQuotation.setQuotaionno(ConfigConstant.generateQuotationNo());
		scQuotationService.save(scQuotation);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("work:scquotation:update")
    public R update(@RequestBody ScQuotationEntity scQuotation){
		scQuotationService.updateById(scQuotation);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("work:scquotation:delete")
    public R delete(@RequestBody String[] quotationids){
		scQuotationService.removeByIds(Arrays.asList(quotationids));

        return R.ok();
    }

}
